#include <cstdlib>
#include "configmanager.hpp"

Configmanager				&Configmanager::get_instance()
{
	static Configmanager	instance;

	return (instance);
}

Configmanager::Configmanager()
{

}

Configmanager::~Configmanager()
{
	for (std::map<std::string, Df*>::iterator i = _dfmap.begin(); i != _dfmap.end(); ++i)
		delete i->second;
}

Df::Tree									*Configmanager::get(std::string const &name)
{
	std::map<std::string, Df*>::iterator	i;

	if ((i = _dfmap.find(name)) != _dfmap.end())
		return (i->second->_tree);
	else
	{
		Df	*df = new Df(name.c_str());

		if (df->is_good())
			_dfmap[name] = df;
		else
			exit(EXIT_FAILURE);
		return (df->_tree);
	}
}
